<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/6/5
 * Time: 12:01:40
 */
namespace app\common\controller;

use think\Loader;
use think\Controller;
use think\Db;
use think\Session;
/**
 * 后台公用基础控制器
 * Class ApiBase
 * @package app\common\controller
 */
class ApiBase extends Controller
{
    protected function _initialize()
    {
        parent::_initialize();

        $this->getUser();

        $this->getSetup();
        // 输出当前请求控制器（配合后台侧边菜单选中状态）
        $this->assign('controller', Loader::parseName($this->request->controller()));
    }

    /**
     * 获取登录管理员信息
     */
    protected function getUser()
    {
        //echo Session('index_id');
        //Session::delete('index_id');
        if (!Session('index_id')) {
            $this->redirect('api/login/index');
        }else{
            //账号识别
            $index_user = Db::name('user')->find(Session('index_id'));
            if($index_user){
                Session::set('index_id',$index_user['id']);
                $this->assign('index_user', $index_user);
            }else{
                Session::delete('index_id');
            }
        }
    }

    /**
     * 获取站点信息
     */
    protected function getSetup()
    {
        $setup = Db::name('setup')->find(1);
        $this->assign('setup', $setup);
    }

}